from faker import Faker
import base64
import cv2
image = '1.jpg'
fake = Faker()
import numpy as np
def imageToStr(image):
    with open(image, 'rb') as f:
        image_byte = base64.b64encode(f.read())
        # print(type(image_byte))
    image_str = image_byte.decode('ascii')  # byte类型转换为str
    # print(type(image_str))
    return image_str
def strToImage(str,filename):
    image_str= str.encode('ascii')
    image_byte = base64.b64decode(image_str)
    image_json = open(filename, 'wb')
    image_json.write(image_byte)  #将图片存到当前文件的fileimage文件中
    image_json.close()


image1 = imageToStr(image)

def get_registered_user_key():
    return {
        "name":fake.name(),
        "address":fake.address(),
        "created_at":fake.year(),
    }


def get_registered_user_value():
    return {
        "img": image1
    }

if __name__ == "__main__":

    a = "imageKey_331398477940745624_A4408_1_574_81"
    a_list = a.split("_")
    print(a_list)
    with open(image, 'rb') as f:
        img_b = f.read()
    img = cv2.imdecode(np.frombuffer(img_b, np.uint8), cv2.IMREAD_UNCHANGED)
    img1 = cv2.imread(image)
    print(get_registered_user_key())